package fr.ece.ing4.ams;

import java.util.HashSet;
import java.util.Set;

public final class SystemManager {

	private static Set<Airport> airports = new HashSet<Airport>();

	private SystemManager() {
		super();
	}
	
	/**
	 * Returns an instance of Airport
	 * @param code airport code must be 3 chars long
	 * @return the new airport
	 * @throws AMSexception 
	 */
	public static Airport createAirport(String code) throws AMSexception{
		if (code.length() != 3)
			throw new IllegalArgumentException("code must 3 chars long");
		Airport ap = new Airport(code);
		if (!airports .add(ap)) {
			ap = null;
			throw new AMSexception("Airport already exists");
		}
		return ap;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Airport cdg = createAirport("CDG");
			//Airport cdg1 = createAirport("CDG");
			System.out.println(airports);
		} catch (AMSexception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
